import http from '@/api'
import { parseStrEmpty } from '@/utils/common'
import { UserForm, UserQuery, UserVO, UserInfoVO } from '@/api/interface/system/user'
import { DeptVO } from '@/api/interface/system/dept'
/**
 * @name 查询用户列表
 * @param query 参数
 * @returns 返回列表
 */
export const listUserApi = (query: UserQuery) => {
  return http.get<UserVO[]>('/system/user/list', query, { loading: true })
}

/**
 * @name 查询用户详细
 * @param userId userId
 * @returns returns
 */
export const getUserApi = (userId?: string | number) => {
  return http.get<UserInfoVO>(`/system/user/` + parseStrEmpty(userId))
}

/**
 * @name 查询部门下拉树结构
 * @returns returns
 */
export const deptTreeSelectApi = () => {
  return http.get<DeptVO[]>(`/system/user/deptTree`)
}

/**
 * @name 新增用户
 * @returns returns
 */
export const addUserApi = (data: UserForm) => {
  return http.post<any>('/system/user', data, { loading: false })
}

/**
 * @name 修改用户
 * @returns returns
 */
export const updateUserApi = (data: UserForm) => {
  return http.put<any>('/system/user', data, { loading: false })
}

/**
 * @name 删除用户
 * @returns returns
 */
export const delUserApi = (userId: Array<string | number> | string | number) => {
  return http.delete<any>(`/system/user/${userId}`)
}

/**
 * @name 用户状态修改
 * @param userId userId
 * @param status status
 * @returns returns
 */
export const changeUserStatus = (data: { userId: number | string; version: number; status: string }) => {
  return http.put<any>('/system/user/changeStatus', data, { loading: false })
}

/**
 * @name 用户密码重置
 * @param data data
 * @returns returns
 */
export const resetUserPwdApi = (data: any) => {
  return http.put<any>('/system/user/resetPwd', data, { loading: false })
}

/**
 * @name 下载模板
 * @returns returns
 */
export const importTemplateApi = () => {
  return http.downloadPost('/system/user/importTemplate', {})
}

/**
 * @name 导入数据
 * @returns returns
 */
export const importDataApi = (params: FormData) => {
  return http.post('/system/user/importData', params)
}

/**
 * @name 导出下载数据
 * @returns returns
 */
export const exportDownApi = (data: any) => {
  return http.downloadPost('/system/user/export', data, { loading: false })
}

/**
 * @name 导出数据
 * @returns returns
 */
export const exportApi = (data: any) => {
  return http.post('/system/user/export', data)
}

/**
 * @name 用户头像上传
 * @param params params
 * @returns returns
 */
export const uploadAvatarApi = (params: FormData) => {
  return http.post<any>('/system/user/profile/avatar', params)
}

/**
 * @name 查询用户个人信息
 * @returns returns
 */
export const getUserProfileApi = () => {
  return http.get<UserInfoVO>(`/system/user/profile`)
}

/**
 * @name 修改用户个人信息
 * @param data data
 * @returns returns
 */
export const updateUserProfileApi = (data: UserForm) => {
  return http.put<any>('/system/user/profile', data, { loading: false })
}
/**
 * @name 修改用户密码
 * @param data data
 * @returns returns
 */
export const updateUserPwdApi = (data: { oldPassword: string; newPassword: string }) => {
  return http.put<any>('system/user/profile/updatePwd', data, { loading: false })
}
